package com.zofer.study.singleton;

/**
 * @description 双检查单例模式
 * volatile 修饰实例 防止指令重排序
 * @date: 2020/9/29 11:18
 */
public class DoubleCheckSingleton {
    private volatile static DoubleCheckSingleton singleton = null;

    private DoubleCheckSingleton(){};

    public static DoubleCheckSingleton getSingleton(){
        if (singleton == null){
            synchronized (DoubleCheckSingleton.class){
                if (singleton == null){
                    singleton = new DoubleCheckSingleton();
                }
            }
        }
        return singleton;
    }
}
